package user

import (
	"context"
	"go.uber.org/zap"
	"user_srv/config"
	"user_srv/internal/model/dao"
	__ "user_srv/proto"
)

// 实现方法
func (s *UserInfoService) UserLogin(ctx context.Context, req *__.UserLoginRequest) (resp *__.UserLoginResponse, err error) {
	var user dao.User
	config.DB.Where("name=? or mobile=?", req.Name, req.Mobile).Limit(1).Find(&user)
	if user.ID == 0 {
		zap.S().Error("该用户还为注册")
		return
	}
	if user.Password != req.Password {
		zap.S().Error("密码错误")
		return
	}
	return &__.UserLoginResponse{Id: int32(user.ID)}, nil
}
